<template>
	<view class="beijingse">
		<!-- 地址 -->
		<!-- <pickercity :messageInfo="{pickerdzshow:pickerdzshow}" @surecity="surecity"></pickercity> -->
		<!-- <view class="mainpadding ffffff flexleft">
			<view class="margin_right1">
				<u-icon name="map-fill" color="#C8A84F" size="20"></u-icon>
			</view>
			<view class="strongtext xiaohei margin_right1">{{city_text||""}}</view>
			<view class="margin_right1">
				<u-icon name="arrow-down" color="#333333" size="14"></u-icon>
			</view>
		</view> -->
		<view class="mainpadding ffffff flexleft">
			<view class="margin_right1">
				<u-icon name="map-fill" color="#C8A84F" size="20"></u-icon>
			</view>
			<view class="strongtext xiaohei margin_right1">{{mdtext||""}}</view>
			<!-- <view class="margin_right1">
				<u-icon name="arrow-down" color="#333333" size="14"></u-icon>
			</view> -->
		</view>
		<!-- 附近门店 -->
		<view class="mainpadding">
			<view class="xiaohui strongtext nofonweight">附近门店</view>
			<view class="margin_top ffffff radius mainpadding2s" v-for="item in mdList" :key="item.PosId" @click="changemdtext(item)">
				<view class="flexbetween">
					<view class="flexbottom">
						<view class="sanshier xiaohei margin_right1 xiankuan">{{item.PosName}}</view>
						<view class="strongtext xiaohui">距您{{httpRequest.returnKmUnit(Number(item.distance))}}</view>
					</view>
					<view class="flexright" @click.stop="openmap(item)">
						<view class="ershiba xiaolan margin_right1">到这去</view>
						<view class="">
							<u-icon name="map-fill" color="#5AA5FF" size="20"></u-icon>
						</view>
					</view>
				</view>
				<view class="flexleft margin_top1" >
					<view class="margin_right1" @click.stop="phone(item.tel)">
						<u-icon name="phone" color="#999999" size="16"></u-icon>
					</view>
					<view class="strongtext xiaohui" @click="phone(item.tel)">{{item.tel}}</view>
				</view>
				<view class="flexleft margin_top1">
					<view class="margin_right1">
						<u-icon name="phone" color="#999999" size="16"></u-icon>
					</view>
					<view class="strongtext xiaohui">{{item.adres}}</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				httpRequest,
				pickerdzshow:false,
				cityinfo:{},
				city_text:"jj",
				mdtext:"",
				lat:"",
				lng:"",
				mdList:[]
			}
		},
		onLoad(options) {
			this.mdtext = options.name
			this.getlocation()
		},
		methods: {
			changemdtext(item){
				uni.$emit("changemdtext",item)
				uni.navigateBack(1)
			},
			openmap(item){
				uni.openLocation({
				     latitude: Number(item.latitude),//即将传到高德或腾讯地图的终点纬度  必须是数值，字符串无效
				     longitude:Number(item.latitude),//即将传到高德或腾讯地图的终点经度  必须是数值，字符串无效
				     name: item.PosName,//即将传到高德或腾讯地图的店铺名称
				     address: item.adres,//即将传到高德或腾讯地图的详细地址
				     scale: 18
				})
			},
			phone(p) {
				uni.makePhoneCall({
					phoneNumber: p.toString()
				}).catch((e) => {
					// console.log(e)  //用catch(e)来捕获错误{makePhoneCall:fail cancel}
				})
			},
			getlocation() {
				let _this = this
				uni.getLocation({
					type: 'wgs64',
					success: function(res) {
						console.log(res, "获取位置成功");
						_this.lat = res.latitude
						_this.lng = res.longitude
						_this.getmdList()
					},
					fail(err) {
						uni.showModal({
							content: '检测到您没打开定位功能权限，是否去设置打开？',
							confirmText: "确认",
							cancelText: '取消',
							success: (res) => {
								if (res.confirm) {
									uni.openSetting({ //opensetting是调起设置页面的
										success: (res) => {
											console.log(res.authSetting);
											if (res.authSetting ==
												true) { //判断res.authsetting的值是true还是false
												_this.getlocation()
											} else {
												_this.getlocation()
												console.log("拒绝授权");
											}
										}
									})
								} else {
									console.log('取消');
									return false;
								}
							}
						})
						console.log(err, "cuowu");
					}
				});
			},
			getmdList() {
				httpRequest.request('/api/index/shopIndex', 'GET', {
					lat: this.lat,
					lng: this.lng
				}).then(res => {
					this.mdList = res.data
				})
			},
			surecity(e) {
				this.pickerdzshow = false
				if(e){
					this.cityinfo = e
					this.city_text = e.provence + "/" + e.city
					console.log(e,999);
				}
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>